package com.blog.controller;

import com.blog.domain.ResponseResult;
import com.blog.domain.entity.User;
import com.blog.enums.AppHttpCodeEnum;
import com.blog.exception.SystemException;
import com.blog.service.BlogLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BlogLoginController {

	@Autowired
	private BlogLoginService blogLoginService;

	/**登录
	 *
	 * @param user
	 * @return
	 */
	@PostMapping("/login")
	public ResponseResult login(@RequestBody User user){
		//未填写用户名
		if (!StringUtils.hasText(user.getUserName())){
			throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
		}

		return blogLoginService.login(user);

	}

	/**退出登录
	 *
	 * @return
	 */

	@PostMapping("/logout")
	public ResponseResult logout(){
		return blogLoginService.logout();
	}

}
